package cn.wl;

import cn.wl.config.RabbitmqConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class Rev {
    //监听email队列
    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_EMAIL})
    public void receiveEmail(String msg, Message message, Channel channel) {
        System.out.println("Email消息内容:"+msg);
        //消息处理完，手动签收
        try {
            channel.basicAck(
                    message.getMessageProperties().getDeliveryTag(),//获取消息的标签--相当于id
                    false);//是否签收所有消息
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //监听sms队列
    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_SMS})
    public void receiveSms(String msg, Message message, Channel channel) {
        System.out.println("Sms消息内容:"+msg);
        //消息处理完，手动签收
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
